import 'package:casdon/core/network/api_client_provider.dart';
import 'package:casdon/modules/home/application/notification/device_list_notifier.dart';
import 'package:casdon/modules/home/application/notification/home_banner_list_notifier.dart';
import 'package:casdon/modules/home/data/api/popup_list_api.dart';
import 'package:casdon/modules/home/data/api/splash_list_api.dart';
import 'package:casdon/modules/home/data/repository/home_repository.dart';
import 'package:casdon/modules/home/data/repository/home_repository_impl.dart';
import 'package:casdon/modules/home/domain/states/home_banner_list_state.dart';
import 'package:casdon/modules/home/domain/states/unified_device_list_state.dart';
import 'package:casdon/modules/home/domain/usecase/ciot_device_list_usecase.dart';
import 'package:casdon/modules/home/domain/usecase/home_banner_list_usecase.dart';
import 'package:casdon/modules/home/domain/usecase/popup_list_usecase.dart';
import 'package:casdon/modules/home/domain/usecase/splash_list_usecase.dart';
import 'package:casdon/modules/home/domain/usecase/user_info_usecase.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

final authUserInfoUsecaseProvider = Provider(
  (ref) => AuthUserInfoUsecase(ref.read(homeRepositoryProvider)),
);
final ciotDeviceListUsecaseProvider = Provider(
  (ref) => CiotDeviceListUsecase(ref.read(homeRepositoryProvider)),
);
final homeBannerListUsercaseProvider = Provider(
  (ref) => HomeBannerListUsecase(ref.read(homeRepositoryProvider)),
);

final homeRepositoryProvider = Provider<HomeRepository>(
  (ref) => HomeRepositoryImpl(ref.read(apiClientProvider)),
);

final splashListUsecaseProvider = Provider(
  (ref) => SplashListUsecase(ref.read(homeRepositoryProvider)),
);

final popupListUsecaseProvider = Provider(
  (ref) => PopupListUsecase(ref.read(homeRepositoryProvider)),
);

// notifier
final homeBannerListNotifierProvider =
    AsyncNotifierProvider<HomeBannerListNotifier, HomeBannerListState>(
      HomeBannerListNotifier.new,
    );
final unifiedDeviceNotifierProvider =
    AsyncNotifierProvider<DiviceListNotifier, UnifiedDeviceListState>(
      DiviceListNotifier.new,
    );

final splashListProvider = FutureProvider<List<ResponseSplashListApi>?>((
  ref,
) async {
  ref.keepAlive();
  return ref.read(splashListUsecaseProvider).execute();
});

final popupListProvider = FutureProvider<List<ResponsePopupListApi>?>((
  ref,
) async {
  ref.keepAlive();
  return ref.read(popupListUsecaseProvider).execute();
});
